/**
 * fmMain.java
 *
 * Created on 21 Март 2008 г., 0:22
 */
package trim.gui.testing;

import com.sun.java.swing.plaf.motif.MotifLookAndFeel;
import com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.LookAndFeel;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.multi.MultiLookAndFeel;
import javax.swing.plaf.synth.SynthLookAndFeel;
import trim.Trim;
import trim.common.Format;
import trim.common.inputdata.FormatOrder;
import trim.common.Material;
import trim.common.inputdata.MaterialStock;
import trim.common.inputdata.InputData;
import trim.common.inputdata.InputDataException;
import trim.common.result.TrimResult;
import trim.gui.testing.components.CloseTabsTabbedPane;
import trim.gui.testing.components.MenuButton;
import trim.gui.testing.components.ResultListPanel;
import trim.gui.testing.models.IRowManipulationTableModel;
import trim.gui.testing.models.PropertiesTableModel;
import trim.gui.testing.models.RequestFormatsModel;
import trim.gui.testing.models.RequestMaterialsModel;
import trim.gui.testing.models.ResultListTableModel;
import trim.gui.testing.models.ResultTableModel;
import trim.gui.testing.objects.ResultsListItem;

/**
 *
 * @author  Дмитрий
 */
public class FmMain extends javax.swing.JFrame
{

  JFileChooser fileChooser;
  private InputData mainInputData;
  //private RequestModel requestModel=new RequestModel();
  //private RequestModel resRequestModel=new RequestModel();
  private RequestFormatsModel requestFormatsModel;
  private RequestMaterialsModel requestMaterialsModel;
  private PropertiesTableModel propertiesTableModel;
  private ResultTableModel resultModel=new ResultTableModel();
  private ResultListTableModel resultListTableModel=new ResultListTableModel();
  private MenuButton runButton;
  TestingDialog testingDialog=new TestingDialog(this,true,resultListTableModel);

  /** Creates new form fmMain */
  public FmMain()
  {
    fileChooser=new JFileChooser();
    fileChooser.setDialogTitle("Choose file");
    mainInputData=new InputData();
    requestFormatsModel=new RequestFormatsModel(mainInputData);
    requestMaterialsModel=new RequestMaterialsModel(mainInputData);
    propertiesTableModel=new PropertiesTableModel();
    propertiesTableModel.addTableModelListener(requestFormatsModel);
    propertiesTableModel.addTableModelListener(requestMaterialsModel);
    initComponents();
    afterInitComponents();
  }

  public ResultListTableModel getResultListTableModel()
  {
    return resultListTableModel;
  }

  private void afterInitComponents()
  {
    JPanel p=new ResultListPanel(resultListTableModel,resultTabbedPane);
    p.setPreferredSize(new Dimension(600,200));
    jSplitPane1.setRightComponent(p);

    runButton=new MenuButton();
    jToolBarMain.add(runButton);
    jToolBarMain.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
    runButton.setText("Run");
    runButton.addMenuButtonActionListener(new ActionListener()
    {

      public void actionPerformed(ActionEvent e)
      {
        runButtonMenuShow();
      }
    });
    runButton.addButtonActionListener(new ActionListener()
    {

      public void actionPerformed(ActionEvent e)
      {
        runCalculation(e);
      }
    });
  }

  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPopupFormats = new javax.swing.JPopupMenu();
    jpmAddLine = new javax.swing.JMenuItem();
    jpmRemoveLine = new javax.swing.JMenuItem();
    jToolBarMain = new javax.swing.JToolBar();
    btTesting = new javax.swing.JButton();
    jSplitPane1 = new javax.swing.JSplitPane();
    jsplitMain = new javax.swing.JSplitPane();
    jSplitPane2 = new javax.swing.JSplitPane();
    inputDataTabbedPane = new javax.swing.JTabbedPane();
    jFormatsSP = new javax.swing.JScrollPane();
    jtRequestFormats = new javax.swing.JTable();
    materialScrolPane = new javax.swing.JScrollPane();
    jtRequestMaterials = new javax.swing.JTable();
    propertiesScrollPane = new javax.swing.JScrollPane();
    propetiesTable = new javax.swing.JTable();
    resultTabbedPane = new CloseTabsTabbedPane();
    menuBar = new javax.swing.JMenuBar();
    fileMenu = new javax.swing.JMenu();
    openMenuItem = new javax.swing.JMenuItem();
    saveMenuItem = new javax.swing.JMenuItem();
    saveAsMenuItem = new javax.swing.JMenuItem();
    exitMenuItem = new javax.swing.JMenuItem();
    toolsMenu = new javax.swing.JMenu();
    plaginsMenuItem = new javax.swing.JMenuItem();
    scriptsMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    aboutMenuItem = new javax.swing.JMenuItem();

    jpmAddLine.setText("Add Item");
    jpmAddLine.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jpmAddLineActionPerformed(evt);
      }
    });
    jPopupFormats.add(jpmAddLine);

    jpmRemoveLine.setText("Remove Item");
    jpmRemoveLine.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jpmRemoveLineActionPerformed(evt);
      }
    });
    jPopupFormats.add(jpmRemoveLine);

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Charon Freamework");

    jToolBarMain.setRollover(true);

    btTesting.setText("Testing");
    btTesting.setDoubleBuffered(true);
    btTesting.setFocusPainted(false);
    btTesting.setFocusable(false);
    btTesting.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    btTesting.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    btTesting.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btTestingActionPerformed(evt);
      }
    });
    jToolBarMain.add(btTesting);

    jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
    jSplitPane1.setResizeWeight(0.75);
    jSplitPane1.setOneTouchExpandable(true);

    jsplitMain.setDividerLocation(260);
    jsplitMain.setOneTouchExpandable(true);
    jsplitMain.setPreferredSize(new java.awt.Dimension(400, 300));

    jSplitPane2.setDividerLocation(250);
    jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
    jSplitPane2.setResizeWeight(0.7);

    inputDataTabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        inputDataTabbedPaneStateChanged(evt);
      }
    });

    jFormatsSP.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseReleased(java.awt.event.MouseEvent evt) {
        jFormatsSPMouseReleased(evt);
      }
    });

    jtRequestFormats.setAutoCreateRowSorter(true);
    jtRequestFormats.setModel(requestFormatsModel);
    jtRequestFormats.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(java.awt.event.MouseEvent evt) {
        jtRequestFormatsMouseClicked(evt);
      }
      public void mousePressed(java.awt.event.MouseEvent evt) {
        jtRequestFormatsMousePressed(evt);
      }
      public void mouseReleased(java.awt.event.MouseEvent evt) {
        jtRequestFormatsMouseReleased(evt);
      }
    });
    jFormatsSP.setViewportView(jtRequestFormats);

    inputDataTabbedPane.addTab("Вектор требований", jFormatsSP);

    materialScrolPane.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseReleased(java.awt.event.MouseEvent evt) {
        materialScrolPaneMouseReleased(evt);
      }
    });

    jtRequestMaterials.setAutoCreateRowSorter(true);
    jtRequestMaterials.setModel(requestMaterialsModel);
    jtRequestMaterials.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(java.awt.event.MouseEvent evt) {
        jtRequestMaterialsMouseClicked(evt);
      }
      public void mousePressed(java.awt.event.MouseEvent evt) {
        jtRequestMaterialsMousePressed(evt);
      }
      public void mouseReleased(java.awt.event.MouseEvent evt) {
        jtRequestMaterialsMouseReleased(evt);
      }
    });
    materialScrolPane.setViewportView(jtRequestMaterials);

    inputDataTabbedPane.addTab("Материал", materialScrolPane);

    jSplitPane2.setTopComponent(inputDataTabbedPane);

    propetiesTable.setModel(propertiesTableModel
    );
    propetiesTable.setMaximumSize(new java.awt.Dimension(300, 64));
    propertiesScrollPane.setViewportView(propetiesTable);

    jSplitPane2.setRightComponent(propertiesScrollPane);

    jsplitMain.setLeftComponent(jSplitPane2);

    resultTabbedPane.addContainerListener(new java.awt.event.ContainerAdapter() {
      public void componentRemoved(java.awt.event.ContainerEvent evt) {
        resultTabbedPaneComponentRemoved(evt);
      }
    });
    jsplitMain.setRightComponent(resultTabbedPane);

    jSplitPane1.setLeftComponent(jsplitMain);

    fileMenu.setText("File");

    openMenuItem.setText("Open");
    openMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        openMenuItemActionPerformed(evt);
      }
    });
    fileMenu.add(openMenuItem);

    saveMenuItem.setText("Save");
    saveMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        saveMenuItemActionPerformed(evt);
      }
    });
    fileMenu.add(saveMenuItem);

    saveAsMenuItem.setText("Save As ...");
    fileMenu.add(saveAsMenuItem);

    exitMenuItem.setText("Exit");
    exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        exitMenuItemActionPerformed(evt);
      }
    });
    fileMenu.add(exitMenuItem);

    menuBar.add(fileMenu);

    toolsMenu.setText("Tools");

    plaginsMenuItem.setText("Plagins");
    plaginsMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        plaginsMenuItemActionPerformed(evt);
      }
    });
    toolsMenu.add(plaginsMenuItem);

    scriptsMenuItem.setText("Scripts");
    scriptsMenuItem.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        scriptsMenuItemActionPerformed(evt);
      }
    });
    toolsMenu.add(scriptsMenuItem);

    menuBar.add(toolsMenu);

    helpMenu.setText("Help");

    aboutMenuItem.setText("About");
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    setJMenuBar(menuBar);

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 964, Short.MAX_VALUE)
      .add(jToolBarMain, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 964, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(layout.createSequentialGroup()
        .add(jToolBarMain, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
        .add(0, 0, 0)
        .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 510, Short.MAX_VALUE))
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  /**
   * Старт вычислений
   * @param e
   */
  private void runCalculation(ActionEvent e)
  {
    List<Trim> lm=AppState.getPlaginManager().getUsedMethods();
    List<InputData> l=new ArrayList(1);
    l.add(mainInputData);
    TestsRunner tr=new TestsRunner(l,lm);
    tr.addListener(new TestRunnerListener()
    {

      public void newResultEvent(InputData inputData,TrimResult tr,Trim method,long time)
      {
        resultListTableModel.addResult(new ResultsListItem(tr,method,mainInputData.clone(),time));
      }
    });
    tr.startTests();
    /*for(Trim t:lm)
    {
    try
    {
    //resultTabbedPane.addTab(t.getClass().getSimpleName(),new ResultTabPanel(t.solve(mainInputData)));
    resultListTableModel.addResult(new ResultsListItem(t.solve(mainInputData),t,mainInputData));
    }catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }*/
  }

  /**
   * Отображение меню кнопки запуска расчетов. Заполняется методами решения ЗФР.
   */
  private void runButtonMenuShow()
  {
    runButton.clearMenu();
    JMenuItem item=new JCheckBoxMenuItem("Select all",true);
    ActionListener al=new ActionListener()
    {

      public void actionPerformed(ActionEvent e)
      {
        PlaginManager pm=AppState.getPlaginManager();
        for(int i=0;i<pm.getMethodsCount();i++)
        {
          pm.setMethodUsed(i,!((JCheckBoxMenuItem)e.getSource()).isSelected());
        }
      }
    };
    item.addActionListener(al);
    runButton.add(item);
    item=new JCheckBoxMenuItem("Unselect all",false);
    item.addActionListener(al);
    runButton.add(item);
    runButton.add(new JSeparator());
    PlaginManager pm=AppState.getPlaginManager();

    class AL implements ActionListener
    {

      int num;

      AL(int i)
      {
        num=i;
      }

      public void actionPerformed(ActionEvent e)
      {
        AppState.getPlaginManager().setMethodUsed(num,((JCheckBoxMenuItem)e.getSource()).isSelected());
      }
    }
    for(int i=0;i<pm.getMethodsCount();i++)
    {
      item=new JCheckBoxMenuItem(pm.getMethod(i).getName(),pm.isMethodUsed(i));
      item.setToolTipText(pm.getMethod(i).getDescription());
      item.addActionListener(new AL(i));
      runButton.add(item);
    }
  }

  private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_saveMenuItemActionPerformed
  {//GEN-HEADEREND:event_saveMenuItemActionPerformed
    fileChooser=new JFileChooser(AppState.CURRENT_FILE);
    int r=fileChooser.showSaveDialog(this);
    if(r==JFileChooser.APPROVE_OPTION)
    {
      try
      {
        File f=fileChooser.getSelectedFile();
        if(!f.getName().toLowerCase().endsWith(".xml"))
          f=new File(f.getAbsolutePath()+".xml");
				this.setTitle(f.getName()+" - Charon Framework");
        AppState.CURRENT_FILE=f.getParentFile();
        mainInputData.saveDataToXML(f);
      }catch(InputDataException ex)
      {
        ex.printStackTrace();
      }
    }
  }//GEN-LAST:event_saveMenuItemActionPerformed

  private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt)
  {
    try
    {
      fileChooser=new JFileChooser(AppState.CURRENT_FILE);
      int returnVal=fileChooser.showOpenDialog(this);
      if(returnVal==JFileChooser.APPROVE_OPTION)
      {
        File f=fileChooser.getSelectedFile();
//        if(!f.getName().toLowerCase().endsWith(".xml"))
//          f=new File(f.getAbsolutePath()+".xml");
        this.setTitle(f.getName()+" - Charon Framework");
        AppState.CURRENT_FILE=f.getParentFile();
        InputStream is;
        is=new FileInputStream(fileChooser.getSelectedFile());
        if(fileChooser.getSelectedFile().getName().toLowerCase().endsWith(".xml"))
          loadFromXML(is);
        else
          loadOldFormat(is);

        requestFormatsModel.fireTableDataChanged();
        requestMaterialsModel.fireTableDataChanged();
      }
    }catch(Exception ex)
    {
      ex.printStackTrace();
    }
  }

  private void loadFromXML(InputStream is) throws InputDataException
  {
    mainInputData.loadDataFromXML(is);
    requestFormatsModel=new RequestFormatsModel(mainInputData);
    requestMaterialsModel=new RequestMaterialsModel(mainInputData);
    jtRequestFormats.setModel(requestFormatsModel);
    jtRequestMaterials.setModel(requestMaterialsModel);

  }

  public InputData getMainInputData()
  {
    return mainInputData;
  }

  /**
   * Загруска входных данных в виде
   * <pre>
   * 8440
   * 320 10
   * 500 3
   * 800 22
   * ............
   * </pre>
   * @param is
   * @throws java.io.IOException
   */
  private void loadOldFormat(InputStream is) throws IOException
  {
    BufferedReader reader=new BufferedReader(new InputStreamReader(is));
    String s;
    boolean b=true;
    int len=0;

    mainInputData.getFormatOrderList().clear();
    mainInputData.getMaterialStockList().clear();
    while((s=reader.readLine())!=null)
    {
      String[] as=s.split("[ \t]");
      if(b)
      {
        len=Integer.parseInt(as[0]);
        mainInputData.getMaterialStockList().add(new MaterialStock(new Material(len),Integer.MAX_VALUE/2));
        b=false;
      }else
      {
        mainInputData.getFormatOrderList().add(new FormatOrder(new Format(Integer.parseInt(as[0])),Integer.parseInt(as[as.length-1])));
      }
    }
  }

  private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_exitMenuItemActionPerformed
  {
    System.exit(0);
  }//GEN-LAST:event_exitMenuItemActionPerformed

  private void jtRequestFormatsMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jtRequestFormatsMouseReleased
  {//GEN-HEADEREND:event_jtRequestFormatsMouseReleased
    if(evt.isPopupTrigger())
      jPopupFormats.show(evt.getComponent(),evt.getX(),evt.getY());
  }//GEN-LAST:event_jtRequestFormatsMouseReleased

  private void jFormatsSPMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jFormatsSPMouseReleased
  {//GEN-HEADEREND:event_jFormatsSPMouseReleased
    if(evt.isPopupTrigger())
      jPopupFormats.show(evt.getComponent(),evt.getX(),evt.getY());
  }//GEN-LAST:event_jFormatsSPMouseReleased

  private void jpmAddLineActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jpmAddLineActionPerformed
  {//GEN-HEADEREND:event_jpmAddLineActionPerformed
    JTable tab=(JTable)(((JScrollPane)inputDataTabbedPane.getSelectedComponent()).getViewport().getComponent(0));
    IRowManipulationTableModel tm=(IRowManipulationTableModel)tab.getModel();
    tm.addRow();
  }//GEN-LAST:event_jpmAddLineActionPerformed

  private void jpmRemoveLineActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jpmRemoveLineActionPerformed
  {//GEN-HEADEREND:event_jpmRemoveLineActionPerformed
    JTable tab=(JTable)((JComponent)inputDataTabbedPane.getSelectedComponent()).getComponents()[0];
    IRowManipulationTableModel tm=(IRowManipulationTableModel)tab.getModel();
    tm.addRow();
    int row=tab.getSelectedRow();
    if(row<0)
      return;
    row=tab.convertRowIndexToModel(row);
    tm.removeRow(row);
  }//GEN-LAST:event_jpmRemoveLineActionPerformed

  private void jtRequestFormatsMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jtRequestFormatsMouseClicked
  {//GEN-HEADEREND:event_jtRequestFormatsMouseClicked
    JTable tab=(JTable)evt.getSource();
    int index=tab.convertRowIndexToModel(tab.getSelectedRow());
    if(index<0)
    {
      propertiesTableModel.setObject(null);
    }else
    {
      propertiesTableModel.setObject(((IRowManipulationTableModel)tab.getModel()).getObject(index));
    }
  }//GEN-LAST:event_jtRequestFormatsMouseClicked

  private void inputDataTabbedPaneStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_inputDataTabbedPaneStateChanged
  {//GEN-HEADEREND:event_inputDataTabbedPaneStateChanged
    propertiesTableModel.setObject(null);

}//GEN-LAST:event_inputDataTabbedPaneStateChanged

  private void jtRequestMaterialsMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jtRequestMaterialsMouseReleased
  {//GEN-HEADEREND:event_jtRequestMaterialsMouseReleased
    if(evt.isPopupTrigger())
      jPopupFormats.show(evt.getComponent(),evt.getX(),evt.getY());
  }//GEN-LAST:event_jtRequestMaterialsMouseReleased

  private void materialScrolPaneMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_materialScrolPaneMouseReleased
  {//GEN-HEADEREND:event_materialScrolPaneMouseReleased
    if(evt.isPopupTrigger())
      jPopupFormats.show(evt.getComponent(),evt.getX(),evt.getY());
  }//GEN-LAST:event_materialScrolPaneMouseReleased

  private void jtRequestMaterialsMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jtRequestMaterialsMouseClicked
  {//GEN-HEADEREND:event_jtRequestMaterialsMouseClicked
    jtRequestFormatsMouseClicked(evt);
  }//GEN-LAST:event_jtRequestMaterialsMouseClicked

  private void plaginsMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_plaginsMenuItemActionPerformed
  {//GEN-HEADEREND:event_plaginsMenuItemActionPerformed
    PlaginsDialog plaginsDialog=new PlaginsDialog(this,AppState.getPlaginManager(),true);
    plaginsDialog.setLocationRelativeTo(this);
    plaginsDialog.setVisible(true);

  }//GEN-LAST:event_plaginsMenuItemActionPerformed

  private void resultTabbedPaneComponentRemoved(java.awt.event.ContainerEvent evt)//GEN-FIRST:event_resultTabbedPaneComponentRemoved
  {//GEN-HEADEREND:event_resultTabbedPaneComponentRemoved
    resultListTableModel.getResultsTableModel().hideResult(evt.getChild());
  }//GEN-LAST:event_resultTabbedPaneComponentRemoved

  private void btTestingActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btTestingActionPerformed
  {//GEN-HEADEREND:event_btTestingActionPerformed

    testingDialog.setLocationRelativeTo(this);
    testingDialog.setVisible(true);
  }//GEN-LAST:event_btTestingActionPerformed
  ScriptWindow scriptWindow=null;
  private void scriptsMenuItemActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_scriptsMenuItemActionPerformed
  {//GEN-HEADEREND:event_scriptsMenuItemActionPerformed
    if(scriptWindow==null)
      scriptWindow=new ScriptWindow(this,true);
    scriptWindow.setLocationRelativeTo(this);
    scriptWindow.setVisible(true);
  }//GEN-LAST:event_scriptsMenuItemActionPerformed

	private void jtRequestFormatsMousePressed(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jtRequestFormatsMousePressed
	{//GEN-HEADEREND:event_jtRequestFormatsMousePressed
if(evt.isPopupTrigger())
      jPopupFormats.show(evt.getComponent(),evt.getX(),evt.getY());
	}//GEN-LAST:event_jtRequestFormatsMousePressed

	private void jtRequestMaterialsMousePressed(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jtRequestMaterialsMousePressed
	{//GEN-HEADEREND:event_jtRequestMaterialsMousePressed
    if(evt.isPopupTrigger())
      jPopupFormats.show(evt.getComponent(),evt.getX(),evt.getY());
	}//GEN-LAST:event_jtRequestMaterialsMousePressed




  /**
   * @param args the command line arguments
   */
  public static void main(String args[])
  {
    java.awt.EventQueue.invokeLater(new Runnable()
    {

      public void run()
      {
        try
        {
          //UIManager.setLookAndFeel(new WindowsLookAndFeel());
          UIManager.setLookAndFeel(new MetalLookAndFeel());
        }catch(UnsupportedLookAndFeelException ex)
        {
          Logger.getLogger(FmMain.class.getName()).log(Level.SEVERE,null,ex);
        }
        FmMain fm=new FmMain();
        fm.setLocationByPlatform(true);
        fm.setVisible(true);
      }
    });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JMenuItem aboutMenuItem;
  private javax.swing.JButton btTesting;
  private javax.swing.JMenuItem exitMenuItem;
  private javax.swing.JMenu fileMenu;
  private javax.swing.JMenu helpMenu;
  private javax.swing.JTabbedPane inputDataTabbedPane;
  private javax.swing.JScrollPane jFormatsSP;
  private javax.swing.JPopupMenu jPopupFormats;
  private javax.swing.JSplitPane jSplitPane1;
  private javax.swing.JSplitPane jSplitPane2;
  private javax.swing.JToolBar jToolBarMain;
  private javax.swing.JMenuItem jpmAddLine;
  private javax.swing.JMenuItem jpmRemoveLine;
  private javax.swing.JSplitPane jsplitMain;
  private javax.swing.JTable jtRequestFormats;
  private javax.swing.JTable jtRequestMaterials;
  private javax.swing.JScrollPane materialScrolPane;
  private javax.swing.JMenuBar menuBar;
  private javax.swing.JMenuItem openMenuItem;
  private javax.swing.JMenuItem plaginsMenuItem;
  private javax.swing.JScrollPane propertiesScrollPane;
  private javax.swing.JTable propetiesTable;
  private javax.swing.JTabbedPane resultTabbedPane;
  private javax.swing.JMenuItem saveAsMenuItem;
  private javax.swing.JMenuItem saveMenuItem;
  private javax.swing.JMenuItem scriptsMenuItem;
  private javax.swing.JMenu toolsMenu;
  // End of variables declaration//GEN-END:variables

  public RequestFormatsModel getRequestFormatsModel()
  {
    return requestFormatsModel;
  }

  public ResultTableModel getResultModel()
  {
    return resultModel;
  }
}
